package longrise.phone.com.bjjt_henan.main;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.baidu.mobstat.StatService;
import com.longrise.bjjt.util.UiUtil;

import longrise.phone.com.bjjt_henan.R;
import longrise.phone.com.bjjt_henan.Utils.WebViewHelper;

/**
 * 用户使用示例界面
 */
public class UserGuideActivity extends Activity {

    public static final String CONSULT_RESP = "http://www.rabbitpre.com/m/q6RBJ3Y";//协商定责
    public static final String POLICE_RESP = "http://www.rabbitpre.com/m/FRQuaaqqg";//交警定责
    public static final String INSTRUCTIONS = "http://www.rabbitpre.com/m/QrANzyE";//使用说明

    private TextView titleTView;

    private WebViewHelper webViewHelper;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //无title
        requestWindowFeature(Window.FEATURE_NO_TITLE);

        LinearLayout bodyLayout = new LinearLayout(this);
        bodyLayout.setOrientation(LinearLayout.VERTICAL);
        //标题栏
        View titleView = View.inflate(this, R.layout.common_titlehn_layout, null);
        LinearLayout.LayoutParams titleParams = new LinearLayout.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT, UiUtil.dip2Px(50));
        bodyLayout.addView(titleView, titleParams);
        titleParams = null;
        //网页
        if (null == webViewHelper) {
            webViewHelper = new WebViewHelper(this);
        }
        View webView = webViewHelper.getView();
        LinearLayout.LayoutParams webParams = new LinearLayout.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
        bodyLayout.addView(webView, webParams);
        webParams = null;

        setContentView(bodyLayout);

        initViews();
        initValues();
    }

    private void initViews() {
        // 返回操作
        findViewById(R.id.hn_btn_back).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });
        // 标题
        titleTView = (TextView) findViewById(R.id.tv_title);
    }

    private void initValues() {
        String title = getIntent().getStringExtra("title");
        titleTView.setText(title);
        String url = getIntent().getStringExtra("url");
        webViewHelper.loadUrl(url);
    }

    @Override
    public void onResume() {
        StatService.onResume(this);
        super.onResume();
    }

    @Override
    public void onPause() {
        StatService.onPause(this);
        super.onPause();
    }

    @Override
    protected void onDestroy() {
        if (null != webViewHelper) {
            webViewHelper.closeView();
        }
        webViewHelper = null;
        super.onDestroy();
    }
}
